package cn.wetcland.panel;

import cn.util.TCUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class SignInPanel {

    /**
     * 获得玩家签到面板
     *
     * @param player 玩家
     * @return 面板实例
     */
    public static Inventory getPlayerSignInPanel(Player player) {
        Inventory inventory = Bukkit.createInventory(null, 45, "§a签到系统");
        Calendar instance = Calendar.getInstance();
        int year = instance.get(Calendar.YEAR);
        // 加一的原因：月份从 0 开始计数
        int month = instance.get(Calendar.MONTH) + 1;
        int day = instance.get(Calendar.DAY_OF_MONTH);
        int monthDay = TCUtil.getMonthDay(month);
        List<Integer> signInYaml = TCUtil.getSignInYaml(player.getName());
        for (int i = 1; i <= monthDay; i++) {
            ItemStack itemStack = new ItemStack(Material.ICE);
            ItemMeta itemMeta = itemStack.getItemMeta();
            if (signInYaml.contains(i)) {
                itemMeta.setDisplayName("§a" + year + "年" + month + "月" + i + "日已签到");
                itemStack.setType(Material.SUNFLOWER);
            } else {
                if (i <= day) {
                    itemMeta.setDisplayName("§c" + year + "年" + month + "月" + i + "日未签到");
                } else {
                    itemMeta.setDisplayName("§b" + year + "年" + month + "月" + i + "日待签到");
                }
            }
            itemStack.setItemMeta(itemMeta);
            inventory.addItem(itemStack);
        }
        ItemStack bottomDesc = new ItemStack(Material.BARREL);
        ItemMeta itemMeta = bottomDesc.getItemMeta();
        itemMeta.setDisplayName("§a签到说明");
        ArrayList<String> strings = new ArrayList<>();
        strings.add("§a月初签到既得 §b1000金币和5节操币");
        strings.add("§a连续签到3天既得 §b2000金币和1节操币");
        strings.add("§a连续签到7天既得 §b4000金币和3节操币");
        strings.add("§a连续签到10天既得 §b6000金币和5节操币");
        strings.add("§a连续签到15天既得 §b8000金币和7节操币");
        strings.add("§a连续签到20天既得 §b10000金币和9节操币");
        strings.add("§a连续签到25天既得 §b15000金币和12节操币");
        strings.add("§a连续签到满月既得 §b30000金币和20节操币");
        itemMeta.setLore(strings);
        bottomDesc.setItemMeta(itemMeta);
        inventory.setItem(40, bottomDesc);
        return inventory;
    }

}
